<template>
  <div class="app-container">
    <div class="search-div">
      <el-form label-width="70px" size="small">
        <el-row>
          <el-col :span="6">
            <el-form-item label="订单编号">
              <el-input style="width: 95%" v-model="searchObj.number" placeholder="订单编号"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row style="display: flex">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="fetchData()"
                     :disabled="$hasBP('bnt.course.list') === false">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetData"
                     :disabled="$hasBP('bnt.course.list') === false">重置</el-button>
        </el-row>
      </el-form>
    </div>

    <!-- 列表 -->
    <el-table v-loading="listLoading" :data="list" stripe border style="width: 100%; margin-top: 10px">
      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column prop="number" label="订单编号" :show-overflow-tooltip="true" align="center"/>
      <el-table-column prop="uname" label="客户姓名" :show-overflow-tooltip="true" align="center"/>
      <el-table-column prop="storeName" label="门店" :show-overflow-tooltip="true" align="center"/>
      <el-table-column prop="coachName" label="教练" :show-overflow-tooltip="true" align="center"/>
      <el-table-column prop="payable" label="应付款" width="100" align="center"/>
      <el-table-column prop="payment" label="实付款" width="100" align="center"/>
    </el-table>

    <!-- 分页组件 -->
    <el-pagination :current-page="page" :total="total" :page-size="limit"
                   style="padding: 30px 0; text-align: center" layout="total, prev, pager, next, jumper"
                   @current-change="fetchData" />
  </div>
</template>

<script>
import orderApi from "@/api/content/orders";

export default {
  data() {
    return {
      listLoading: true, // 数据是否正在加载
      list: null, // banner列表
      total: 0, // 数据库中的总记录数
      page: 1, // 默认页码
      limit: 10, // 每页记录数
      searchObj: {}, // 查询表单对象

      createTimes: [],

      // dialogVisible: false,
      // sysUser: defaultForm,
      // saveBtnDisabled: false,
    };
  },

  // 生命周期函数：内存准备完毕，页面尚未渲染
  created() {
    console.log("list created......");
    this.fetchData();
  },

  // 生命周期函数：内存准备完毕，页面渲染成功
  mounted() {
    console.log("list mounted......");
  },

  methods: {
    // 加载banner列表数据
    fetchData(page = 1) {
      this.page = page;
      orderApi
        .getPageCoachList(this.page, this.limit, this.searchObj)
        .then((response) => {
          this.list = response.data.records;
          this.total = response.data.total;
          // 数据加载并绑定成功
          this.listLoading = false;
        });
    },

    // 重置查询表单
    resetData() {
      console.log("重置查询表单");
      this.searchObj = {};
      this.createTimes = [];
      this.fetchData();
    },
  },
};
</script>
